import Vue from 'vue'
import { Notification } from 'element-ui'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Index from '../views/Index.vue'
import store from '../store/index'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'index',
    component: Index
  },
  {
    path: '/home',
    name: 'home',
    component: Home
  },
  {
    path: '/login',
    name: 'login',
    component: () => import ( /* webpackChunkName: "login" */'@views/Login.vue')
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '@views/About.vue')
  },
  {
    path: '*',
    name: 'pageNotFound',
    component: () => import('@views/404.vue')
  }
]
const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  // showNotification('即将要进入的目标', to.path)
  // showNotification('当前导航正要离开的路由', from.path)
  // showNotification('当前用户信息', store.state.user)
  next()
})
// 信息提示
export function showNotification(
  title = '提示',
  message = '内容',
  duration = 10000,
  position = 'top-left',
  type = 'error'
) {
  var i = 100
  if (typeof message == 'object') {
    message = JSON.stringify(message)
  }
  if (i >= 1000) {
    i = 100
  }
  setTimeout(() => {
    Notification({
      title,
      message,
      // message: to,
      position,
      duration,
      type
    })
    i++
  }, i)
}
export default router
